<?php
require_once("inc.member.php");

$this_title="$vars[member_title] &raquo; ".__("Purchase History");
$page_title=__("Transaction History");
$content_title=__("Transaction History");

$item_per_page=$vars["user_item_per_page"];

require_once("inc.wallet_select.php");

$r_status=array("confirmed","cancelled");
$r_status_d=array("confirmed"=>__("Confirmed"),"cancelled"=>__("Cancelled"));
$r_payment_channel=$vars['dbv']['sale_payment'];
$r_payment_channel_d=$vars['dbv']['sale_payment_d'];

require_once("inc.history_tab.php");

//#####LIST PURCHASE HISTORY#####
$count_sql="select count(*) from $db->purchase where uid='$uid'";
$record_sql="select * from $db->purchase where uid='$uid' order by cdate desc limit <%limit_start%>, <%limit%>";

$cur_page=$_GET["nav"];
$total_record=@mysql_result(mysql_query($count_sql), 0);
$total_page=ceil($total_record/$item_per_page);
$page=($cur_page? ($cur_page>$total_page? $total_page : ($cur_page<1? 1 : $cur_page)) : 1);
$limit_start=($page-1)*$item_per_page;
$nav_link=format_page($page, $total_page, 15);
$this_page_total=@mysql_num_rows($r=mysql_query(str_replace("<%limit_start%>", $limit_start, str_replace("<%limit%>", $item_per_page, $record_sql))));
$k=0;
for($i=0;$i<$this_page_total;$i++){
 $p=mysql_fetch_assoc($r);
 $status_class=$p["status"]=="confirmed"? "green" : "red";
 //get products
 $prod_details='';
 $t2=@mysql_num_rows($r2=mysql_query("select * from $db->purchase_detail where pid='$p[id]'"));
 for($j=0;$j<$t2;$j++){
  $saled=mysql_fetch_assoc($r2);
  $prod_details.="$saled[product_name] x $saled[qty]<br />\n";
 }
 $his_row.="
 <tr class='row$k'>
  <td>$p[id]</td>
  <td class='number'>".number_format($p['total_dp'], 2)."</td>
  <td class='number'>".number_format($p['total_bv'], 2)."</td>
  <td>".$r_payment_channel_d[$p["payment_type"]]."</td>
  <td class='$status_class'>".$r_status_d[$p["status"]]."</td>
  <td>".date($vars['date_format'], strtotime($p["cdate"]))."</td>
 </tr>";
 $k=1-$k;
}

//listing text
$listing_text=replace_tag(__("<%x%> purchase <%record%>."), array("<%x%>"=>"$total_record", "<%record%>"=>$total_record>1? __("records") : __("record")));

//listing
$his_list=
"<h2>".__("Purchase History")."</h2>
$listing_text $nav_link
<table class='pbl_table'>
 <tr class='pbl_header'>
  <td>".__("ID")."</td>
  <td>".__("Amount")." ".__("(").$vars['currency'].__(")")."</td>
  <td>".__("BV")."</td>
  <td>".__("Payment Channel")."</td>
  <td>".__("Status")."</td>
  <td>".__("Date")."</td>
 </tr>
 $his_row
</table>
$nav_link";

$content=$inc_wallet_select.$his_list;
print format_member_page($content, $this_title, $content_title, $css.$jvscript.$inc_jvscript);
?>